{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# xgboost参数调优 on Data Hackathon 3.x\n",
    "数据集来源于Data Hackathon 3.x。该问题是一个金融行业的任务：预测Happy Customer Bank对客户发放贷款的概率。\n",
    "问题描述：https://discuss.analyticsvidhya.com/t/hackathon-3-x-predict-customer-worth-for-happy-customer-bank/3802\n",
    "\n",
    "该问题的优胜解决方案：\n",
    "https://medium.com/data-science-analytics/analytics-vidhya-3-x-hackathon-9f2550b47be6\n",
    "https://github.com/binga/AnalyticsVidhya_3.X_Hackathon"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 特征工程\n",
    "所有的特征处理也只做最基本的参考，可自行尝试更多的特征工程工作。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 加载需要的库:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "from xgboost import XGBClassifier\n",
    "import xgboost as xgb\n",
    "\n",
    "import pandas as pd \n",
    "import numpy as np\n",
    "\n",
    "from sklearn.model_selection import GridSearchCV\n",
    "from sklearn.model_selection import StratifiedKFold\n",
    "\n",
    "from sklearn.metrics import log_loss\n",
    "\n",
    "from matplotlib import pyplot\n",
    "import seaborn as sns\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "#载入数据:\n",
    "dpath = './data/'\n",
    "train = pd.read_csv(dpath + 'RentListingInquries_FE_train.csv')\n",
    "test = pd.read_csv(dpath + 'RentListingInquries_FE_test.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((49352, 228), (74659, 227))"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train.shape, test.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 看看数据的基本情况"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 拿前5条出来看看"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>bathrooms</th>\n",
       "      <th>bedrooms</th>\n",
       "      <th>price</th>\n",
       "      <th>price_bathrooms</th>\n",
       "      <th>price_bedrooms</th>\n",
       "      <th>room_diff</th>\n",
       "      <th>room_num</th>\n",
       "      <th>Year</th>\n",
       "      <th>Month</th>\n",
       "      <th>Day</th>\n",
       "      <th>...</th>\n",
       "      <th>walk</th>\n",
       "      <th>walls</th>\n",
       "      <th>war</th>\n",
       "      <th>washer</th>\n",
       "      <th>water</th>\n",
       "      <th>wheelchair</th>\n",
       "      <th>wifi</th>\n",
       "      <th>windows</th>\n",
       "      <th>work</th>\n",
       "      <th>interest_level</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.5</td>\n",
       "      <td>3</td>\n",
       "      <td>3000</td>\n",
       "      <td>1200.0</td>\n",
       "      <td>750.000000</td>\n",
       "      <td>-1.5</td>\n",
       "      <td>4.5</td>\n",
       "      <td>2016</td>\n",
       "      <td>6</td>\n",
       "      <td>24</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1.0</td>\n",
       "      <td>2</td>\n",
       "      <td>5465</td>\n",
       "      <td>2732.5</td>\n",
       "      <td>1821.666667</td>\n",
       "      <td>-1.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>2016</td>\n",
       "      <td>6</td>\n",
       "      <td>12</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>2850</td>\n",
       "      <td>1425.0</td>\n",
       "      <td>1425.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2016</td>\n",
       "      <td>4</td>\n",
       "      <td>17</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>3275</td>\n",
       "      <td>1637.5</td>\n",
       "      <td>1637.500000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2016</td>\n",
       "      <td>4</td>\n",
       "      <td>18</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1.0</td>\n",
       "      <td>4</td>\n",
       "      <td>3350</td>\n",
       "      <td>1675.0</td>\n",
       "      <td>670.000000</td>\n",
       "      <td>-3.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>2016</td>\n",
       "      <td>4</td>\n",
       "      <td>28</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 228 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   bathrooms  bedrooms  price  price_bathrooms  price_bedrooms  room_diff  \\\n",
       "0        1.5         3   3000           1200.0      750.000000       -1.5   \n",
       "1        1.0         2   5465           2732.5     1821.666667       -1.0   \n",
       "2        1.0         1   2850           1425.0     1425.000000        0.0   \n",
       "3        1.0         1   3275           1637.5     1637.500000        0.0   \n",
       "4        1.0         4   3350           1675.0      670.000000       -3.0   \n",
       "\n",
       "   room_num  Year  Month  Day       ...        walk  walls  war  washer  \\\n",
       "0       4.5  2016      6   24       ...           0      0    0       0   \n",
       "1       3.0  2016      6   12       ...           0      0    0       0   \n",
       "2       2.0  2016      4   17       ...           0      0    0       0   \n",
       "3       2.0  2016      4   18       ...           0      0    0       0   \n",
       "4       5.0  2016      4   28       ...           0      0    1       0   \n",
       "\n",
       "   water  wheelchair  wifi  windows  work  interest_level  \n",
       "0      0           0     0        0     0               1  \n",
       "1      0           0     0        0     0               2  \n",
       "2      0           0     0        0     0               0  \n",
       "3      0           0     0        0     0               2  \n",
       "4      0           0     0        0     0               2  \n",
       "\n",
       "[5 rows x 228 columns]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train.head(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 49352 entries, 0 to 49351\n",
      "Columns: 228 entries, bathrooms to interest_level\n",
      "dtypes: float64(9), int64(219)\n",
      "memory usage: 85.8 MB\n"
     ]
    }
   ],
   "source": [
    "train.info()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 训练参数设置"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "y_train = train['interest_level']\n",
    "train = train.drop([\"interest_level\"], axis=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "max_depth： 树的最大深度。缺省值为6，取值范围为：[1,∞] eta：学习率。为了防止过拟合，更新过程中用到的收缩步长。 eta通过缩减特征的权重使提升计算过程更加保守。缺省值为0.3，取值范围为：[0,1] silent：取0时表示打印出运行时信息，取1时表示以缄默方式运行，不打印运行时信息。缺省值为0 objective： 定义学习任务及相应的学习目标，“binary:logistic” 表示二分类的逻辑回归问题，输出为概率。\n",
    "其他参数取默认值。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "# prepare cross validation\n",
    "kfold = StratifiedKFold(n_splits=5, shuffle=True, random_state=3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZUAAAEKCAYAAADaa8itAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmU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Gab5zsuNeBLytnQ4j\nyaJ2EcG3gDckWdDmXn6vr98uTcc5Fam7BUmuBZ4ArAU+C5w8Sb93J3kVg1HM9cDXgJczWDn3o8AL\nGPxP/4LW/xjgKwyepvlD4ClTfP8Gx62qh5I8D/hOEoD7gP9YVVcn+TxwLYM5nP+1KT9c6spViiVJ\nvfH0lySpN4aKJKk3hookqTeGiiSpN4aKJKk3hookqTeGiiSpN4aKJKk3/x++6iyfp4e+ywAAAABJ\nRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1a16cb7190>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#直接调用xgboost内嵌的交叉验证（cv），可对连续的n_estimators参数进行快速交叉验证\n",
    "#而GridSearchCV只能对有限个参数进行交叉验证\n",
    "def modelfit(alg, X_train, y_train, cv_folds=None, early_stopping_rounds=10):\n",
    "    xgb_param = alg.get_xgb_params()\n",
    "    xgb_param['num_class'] = 9\n",
    "    \n",
    "    #直接调用xgboost，而非sklarn的wrapper类\n",
    "    xgtrain = xgb.DMatrix(X_train, label = y_train)\n",
    "        \n",
    "    cvresult = xgb.cv(xgb_param, xgtrain, num_boost_round=alg.get_params()['n_estimators'], folds =cv_folds,\n",
    "             metrics='mlogloss', early_stopping_rounds=early_stopping_rounds)\n",
    "  \n",
    "    cvresult.to_csv('1_nestimators.csv', index_label = 'n_estimators')\n",
    "    \n",
    "    #最佳参数n_estimators\n",
    "    n_estimators = cvresult.shape[0]\n",
    "    \n",
    "    # 采用交叉验证得到的最佳参数n_estimators，训练模型\n",
    "    alg.set_params(n_estimators = n_estimators)\n",
    "    alg.fit(X_train, y_train, eval_metric='mlogloss')\n",
    "        \n",
    "    #Predict training set:\n",
    "    #train_predprob = alg.predict_proba(X_train)\n",
    "    #logloss = log_loss(y_train, train_predprob)\n",
    "\n",
    "   #Print model report:\n",
    "   # print (\"logloss of train :\" )\n",
    "   # print logloss"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Monthly_Income</th>\n",
       "      <th>Loan_Amount_Applied</th>\n",
       "      <th>Loan_Tenure_Applied</th>\n",
       "      <th>Existing_EMI</th>\n",
       "      <th>Var5</th>\n",
       "      <th>Loan_Amount_Submitted</th>\n",
       "      <th>Loan_Tenure_Submitted</th>\n",
       "      <th>Interest_Rate</th>\n",
       "      <th>Processing_Fee</th>\n",
       "      <th>EMI_Loan_Submitted</th>\n",
       "      <th>Var4</th>\n",
       "      <th>LoggedIn</th>\n",
       "      <th>Disbursed</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>8.702000e+04</td>\n",
       "      <td>8.694900e+04</td>\n",
       "      <td>86949.000000</td>\n",
       "      <td>8.694900e+04</td>\n",
       "      <td>87020.000000</td>\n",
       "      <td>5.240700e+04</td>\n",
       "      <td>52407.000000</td>\n",
       "      <td>27726.000000</td>\n",
       "      <td>27420.000000</td>\n",
       "      <td>27726.000000</td>\n",
       "      <td>87020.000000</td>\n",
       "      <td>87020.000000</td>\n",
       "      <td>87020.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>5.884997e+04</td>\n",
       "      <td>2.302507e+05</td>\n",
       "      <td>2.131399</td>\n",
       "      <td>3.696228e+03</td>\n",
       "      <td>4.961503</td>\n",
       "      <td>3.950106e+05</td>\n",
       "      <td>3.891369</td>\n",
       "      <td>19.197474</td>\n",
       "      <td>5131.150839</td>\n",
       "      <td>10999.528377</td>\n",
       "      <td>2.949805</td>\n",
       "      <td>0.029350</td>\n",
       "      <td>0.014629</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>2.177511e+06</td>\n",
       "      <td>3.542068e+05</td>\n",
       "      <td>2.014193</td>\n",
       "      <td>3.981021e+04</td>\n",
       "      <td>5.670385</td>\n",
       "      <td>3.082481e+05</td>\n",
       "      <td>1.165359</td>\n",
       "      <td>5.834213</td>\n",
       "      <td>4725.837644</td>\n",
       "      <td>7512.323050</td>\n",
       "      <td>1.697720</td>\n",
       "      <td>0.168785</td>\n",
       "      <td>0.120062</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>5.000000e+04</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>11.990000</td>\n",
       "      <td>200.000000</td>\n",
       "      <td>1176.410000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>1.650000e+04</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>2.000000e+05</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>15.250000</td>\n",
       "      <td>2000.000000</td>\n",
       "      <td>6491.600000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>2.500000e+04</td>\n",
       "      <td>1.000000e+05</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>3.000000e+05</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>18.000000</td>\n",
       "      <td>4000.000000</td>\n",
       "      <td>9392.970000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>4.000000e+04</td>\n",
       "      <td>3.000000e+05</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>3.500000e+03</td>\n",
       "      <td>11.000000</td>\n",
       "      <td>5.000000e+05</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>20.000000</td>\n",
       "      <td>6250.000000</td>\n",
       "      <td>12919.040000</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>4.445544e+08</td>\n",
       "      <td>1.000000e+07</td>\n",
       "      <td>10.000000</td>\n",
       "      <td>1.000000e+07</td>\n",
       "      <td>18.000000</td>\n",
       "      <td>3.000000e+06</td>\n",
       "      <td>6.000000</td>\n",
       "      <td>37.000000</td>\n",
       "      <td>50000.000000</td>\n",
       "      <td>144748.280000</td>\n",
       "      <td>7.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       Monthly_Income  Loan_Amount_Applied  Loan_Tenure_Applied  Existing_EMI  \\\n",
       "count    8.702000e+04         8.694900e+04         86949.000000  8.694900e+04   \n",
       "mean     5.884997e+04         2.302507e+05             2.131399  3.696228e+03   \n",
       "std      2.177511e+06         3.542068e+05             2.014193  3.981021e+04   \n",
       "min      0.000000e+00         0.000000e+00             0.000000  0.000000e+00   \n",
       "25%      1.650000e+04         0.000000e+00             0.000000  0.000000e+00   \n",
       "50%      2.500000e+04         1.000000e+05             2.000000  0.000000e+00   \n",
       "75%      4.000000e+04         3.000000e+05             4.000000  3.500000e+03   \n",
       "max      4.445544e+08         1.000000e+07            10.000000  1.000000e+07   \n",
       "\n",
       "               Var5  Loan_Amount_Submitted  Loan_Tenure_Submitted  \\\n",
       "count  87020.000000           5.240700e+04           52407.000000   \n",
       "mean       4.961503           3.950106e+05               3.891369   \n",
       "std        5.670385           3.082481e+05               1.165359   \n",
       "min        0.000000           5.000000e+04               1.000000   \n",
       "25%        0.000000           2.000000e+05               3.000000   \n",
       "50%        2.000000           3.000000e+05               4.000000   \n",
       "75%       11.000000           5.000000e+05               5.000000   \n",
       "max       18.000000           3.000000e+06               6.000000   \n",
       "\n",
       "       Interest_Rate  Processing_Fee  EMI_Loan_Submitted          Var4  \\\n",
       "count   27726.000000    27420.000000        27726.000000  87020.000000   \n",
       "mean       19.197474     5131.150839        10999.528377      2.949805   \n",
       "std         5.834213     4725.837644         7512.323050      1.697720   \n",
       "min        11.990000      200.000000         1176.410000      0.000000   \n",
       "25%        15.250000     2000.000000         6491.600000      1.000000   \n",
       "50%        18.000000     4000.000000         9392.970000      3.000000   \n",
       "75%        20.000000     6250.000000        12919.040000      5.000000   \n",
       "max        37.000000    50000.000000       144748.280000      7.000000   \n",
       "\n",
       "           LoggedIn     Disbursed  \n",
       "count  87020.000000  87020.000000  \n",
       "mean       0.029350      0.014629  \n",
       "std        0.168785      0.120062  \n",
       "min        0.000000      0.000000  \n",
       "25%        0.000000      0.000000  \n",
       "50%        0.000000      0.000000  \n",
       "75%        0.000000      0.000000  \n",
       "max        1.000000      1.000000  "
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(124737, 27)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#合成一个总的data\n",
    "train['source']= 'train'\n",
    "test['source'] = 'test'\n",
    "data=pd.concat([train, test],ignore_index=True)\n",
    "data.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 数据应用/建模一个很重要的工作是检查数据质量：异常点、缺省值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "City                      1401\n",
       "DOB                          0\n",
       "Device_Type                  0\n",
       "Disbursed                37717\n",
       "EMI_Loan_Submitted       84901\n",
       "Employer_Name              113\n",
       "Existing_EMI               111\n",
       "Filled_Form                  0\n",
       "Gender                       0\n",
       "ID                           0\n",
       "Interest_Rate            84901\n",
       "Lead_Creation_Date           0\n",
       "Loan_Amount_Applied        111\n",
       "Loan_Amount_Submitted    49535\n",
       "Loan_Tenure_Applied        111\n",
       "Loan_Tenure_Submitted    49535\n",
       "LoggedIn                 37717\n",
       "Mobile_Verified              0\n",
       "Monthly_Income               0\n",
       "Processing_Fee           85346\n",
       "Salary_Account           16801\n",
       "Source                       0\n",
       "Var1                         0\n",
       "Var2                         0\n",
       "Var4                         0\n",
       "Var5                         0\n",
       "source                       0\n",
       "dtype: int64"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.apply(lambda x: sum(x.isnull()))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 这些字段分别有多少种取值，也可以可以看看分布"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Gender属性的不同取值和出现的次数\n",
      "\n",
      "Male      71398\n",
      "Female    53339\n",
      "Name: Gender, dtype: int64\n",
      "\n",
      "Salary_Account属性的不同取值和出现的次数\n",
      "\n",
      "HDFC Bank                                          25180\n",
      "ICICI Bank                                         19547\n",
      "State Bank of India                                17110\n",
      "Axis Bank                                          12590\n",
      "Citibank                                            3398\n",
      "Kotak Bank                                          2955\n",
      "IDBI Bank                                           2213\n",
      "Punjab National Bank                                1747\n",
      "Bank of India                                       1713\n",
      "Bank of Baroda                                      1675\n",
      "Standard Chartered Bank                             1434\n",
      "Canara Bank                                         1385\n",
      "Union Bank of India                                 1330\n",
      "Yes Bank                                            1120\n",
      "ING Vysya                                            996\n",
      "Corporation bank                                     948\n",
      "Indian Overseas Bank                                 901\n",
      "State Bank of Hyderabad                              854\n",
      "Indian Bank                                          773\n",
      "Oriental Bank of Commerce                            761\n",
      "IndusInd Bank                                        711\n",
      "Andhra Bank                                          706\n",
      "Central Bank of India                                648\n",
      "Syndicate Bank                                       614\n",
      "Bank of Maharasthra                                  576\n",
      "HSBC                                                 474\n",
      "State Bank of Bikaner & Jaipur                       448\n",
      "Karur Vysya Bank                                     435\n",
      "State Bank of Mysore                                 385\n",
      "Federal Bank                                         377\n",
      "Vijaya Bank                                          354\n",
      "Allahabad Bank                                       345\n",
      "UCO Bank                                             344\n",
      "State Bank of Travancore                             333\n",
      "Karnataka Bank                                       279\n",
      "United Bank of India                                 276\n",
      "Dena Bank                                            268\n",
      "Saraswat Bank                                        265\n",
      "State Bank of Patiala                                263\n",
      "South Indian Bank                                    223\n",
      "Deutsche Bank                                        176\n",
      "Abhyuday Co-op Bank Ltd                              161\n",
      "The Ratnakar Bank Ltd                                113\n",
      "Tamil Nadu Mercantile Bank                           103\n",
      "Punjab & Sind bank                                    84\n",
      "J&K Bank                                              78\n",
      "Lakshmi Vilas bank                                    69\n",
      "Dhanalakshmi Bank Ltd                                 66\n",
      "State Bank of Indore                                  32\n",
      "Catholic Syrian Bank                                  27\n",
      "India Bulls                                           21\n",
      "B N P Paribas                                         15\n",
      "Firstrand Bank Limited                                11\n",
      "GIC Housing Finance Ltd                               10\n",
      "Bank of Rajasthan                                      8\n",
      "Kerala Gramin Bank                                     4\n",
      "Industrial And Commercial Bank Of China Limited        3\n",
      "Ahmedabad Mercantile Cooperative Bank                  1\n",
      "Name: Salary_Account, dtype: int64\n",
      "\n",
      "Mobile_Verified属性的不同取值和出现的次数\n",
      "\n",
      "Y    80928\n",
      "N    43809\n",
      "Name: Mobile_Verified, dtype: int64\n",
      "\n",
      "Var1属性的不同取值和出现的次数\n",
      "\n",
      "HBXX    84901\n",
      "HBXC    12952\n",
      "HBXB     6502\n",
      "HAXA     4214\n",
      "HBXA     3042\n",
      "HAXB     2879\n",
      "HBXD     2818\n",
      "HAXC     2171\n",
      "HBXH     1387\n",
      "HCXF      990\n",
      "HAYT      710\n",
      "HAVC      570\n",
      "HAXM      386\n",
      "HCXD      348\n",
      "HCYS      318\n",
      "HVYS      252\n",
      "HAZD      161\n",
      "HCXG      114\n",
      "HAXF       22\n",
      "Name: Var1, dtype: int64\n",
      "\n",
      "Filled_Form属性的不同取值和出现的次数\n",
      "\n",
      "N    96740\n",
      "Y    27997\n",
      "Name: Filled_Form, dtype: int64\n",
      "\n",
      "Device_Type属性的不同取值和出现的次数\n",
      "\n",
      "Web-browser    92105\n",
      "Mobile         32632\n",
      "Name: Device_Type, dtype: int64\n",
      "\n",
      "Var2属性的不同取值和出现的次数\n",
      "\n",
      "B    53481\n",
      "G    47338\n",
      "C    20366\n",
      "E     1855\n",
      "D      918\n",
      "F      770\n",
      "A        9\n",
      "Name: Var2, dtype: int64\n",
      "\n",
      "Source属性的不同取值和出现的次数\n",
      "\n",
      "S122    55249\n",
      "S133    42900\n",
      "S159     7999\n",
      "S143     6140\n",
      "S127     2804\n",
      "S137     2450\n",
      "S134     1900\n",
      "S161     1109\n",
      "S151     1018\n",
      "S157      929\n",
      "S153      705\n",
      "S144      447\n",
      "S156      432\n",
      "S158      294\n",
      "S123      112\n",
      "S141       83\n",
      "S162       60\n",
      "S124       43\n",
      "S150       19\n",
      "S160       11\n",
      "S136        5\n",
      "S138        5\n",
      "S155        5\n",
      "S139        4\n",
      "S129        4\n",
      "S135        2\n",
      "S131        1\n",
      "S130        1\n",
      "S132        1\n",
      "S125        1\n",
      "S140        1\n",
      "S142        1\n",
      "S126        1\n",
      "S154        1\n",
      "Name: Source, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "var = ['Gender','Salary_Account','Mobile_Verified','Var1','Filled_Form','Device_Type','Var2','Source']\n",
    "for v in var:\n",
    "    print '\\n%s属性的不同取值和出现的次数\\n'%v\n",
    "    print data[v].value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### City"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "724"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(data['City'].unique())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### city的取值很多，在此粗暴抛弃\n",
    "也可以保留最常见的10个城市，其他城市编码成非主要城市"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": true,
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "data.drop('City',axis=1,inplace=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### DOB\n",
    "DOB是出生的具体日期，具体日期可能没作用，转换成年龄段"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    23-May-78\n",
       "1    07-Oct-85\n",
       "2    10-Oct-81\n",
       "3    30-Nov-87\n",
       "4    17-Feb-84\n",
       "Name: DOB, dtype: object"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data['DOB'].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    37\n",
       "1    30\n",
       "2    34\n",
       "3    28\n",
       "4    31\n",
       "Name: Age, dtype: int64"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#创建一个年龄的字段Age\n",
    "#因为竞赛在2015年举行，所以用15+100减去年份（最后两位）\n",
    "data['Age'] = data['DOB'].apply(lambda x: 115 - int(x[-2:]))\n",
    "data['Age'].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#把原始的DOB字段去掉:\n",
    "data.drop('DOB',axis=1,inplace=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### EMI_Load_Submitted字段处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x1a17f6b490>"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAY0AAAD9CAYAAABA8iukAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAG55JREFUeJzt3X901fWd5/HnSyKEShVtaw4SzuK0\nnG6Q2ZmpGXRGtycpM4DWLc6cdivtjLRNy8Eqbdd1FMmepdM2MzKdU6e2AosNC3bbYMdpVzq1IovJ\ndrKjVNRW0NQStSMpjNYFWbEa+fHeP+4n9hIuyZd7ubm58fU45558v+/v5/v9fsJJ8uLz+X7v9yoi\nMDMzy+K0SnfAzMyqh0PDzMwyc2iYmVlmDg0zM8vMoWFmZpk5NMzMLDOHhpmZZebQMDOzzBwaZmaW\nWU2lO3Cqvf3tb4/p06dXuhtmx3nllVc444wzKt0Ns4IeeeSRFyPiHcO1G3OhMX36dLZv317pbpgd\np6uri6ampkp3w6wgSf+SpZ2np8zMLDOHhpm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SUVYOhpqeOAN3Ah4GJEfGLvEscxXg38GxE/DytbwCuBf4OaJZ0I/AW\n4BzgCeD7qd3ACOcRYPqJDh4RP5H0W8Bc4I+AhyX9Abk/8kPpSPv/SNKZaSoO4IcRcUjSDnIfVHZf\nqu8Yqh8nMDe9Hkvrk8iFyFuB70XErwEk+dMz38QcGjYWbAS+B3z+FByrYOKkEcgqoDEidqepo9q8\nJv3p6xGG+b2KiIPkQua7ko4Cl5MbIeWP/GsH73aC9f50zKOSDsVv3nh1dLh+FCDgryPivx1TlD5X\n4Pz2JuXpKRsL/gn4a9L/xkv0M2C6pHel9T8H/je/+SP+Yrrb6YPFHFzSJZLOTsvjgZnknsr8PHCu\npLelayhXDNr1w2mfS4EDEXGgmPMDhwaudQAvkxtFDNgMfGLgbi5JUyWdC/wI+BNJEyW9FfgPRZ7b\nxgCPNKwaTJT0k7z1+9L8PADpf9d/W+Sx50jqy1v/EPBx4O8l1QAPA2vSxeo7yE37/CLVi/FOYHW6\niH4a8APgHyIiJH0B2AY8Sy688u2X9M/AmcAnijw35B5l8rikRyPio5L+T7oA/8N0XaMBeDBN8R0E\n/iwiHpV0F/ATcgH3TyWc36qcHyNiZmaZeXrKzMwy8/SUjXmS5gErB5WfjYg/GUvnNBsJnp4yM7PM\nPD1lZmaZOTTMzCwzh4aZmWXm0DAzs8wcGmZmltn/B9JRy3+cNRJ7AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1a173b5b50>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "data.boxplot(column=['EMI_Loan_Submitted'],return_type='axes')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>EMI_Loan_Submitted</th>\n",
       "      <th>EMI_Loan_Submitted_Missing</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>6762.90</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6978.92</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>30824.65</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>10883.38</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   EMI_Loan_Submitted  EMI_Loan_Submitted_Missing\n",
       "0                 NaN                           1\n",
       "1             6762.90                           0\n",
       "2                 NaN                           1\n",
       "3                 NaN                           1\n",
       "4                 NaN                           1\n",
       "5             6978.92                           0\n",
       "6                 NaN                           1\n",
       "7                 NaN                           1\n",
       "8            30824.65                           0\n",
       "9            10883.38                           0"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#缺失值比较多，干脆就开一个新的字段，表明是缺失值还是不是缺失值\n",
    "data['EMI_Loan_Submitted_Missing'] = data['EMI_Loan_Submitted'].apply(lambda x: 1 if pd.isnull(x) else 0)\n",
    "data[['EMI_Loan_Submitted','EMI_Loan_Submitted_Missing']].head(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#原始那一列就可以不要了\n",
    "#data.drop('EMI_Loan_Submitted',axis=1,inplace=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Employer Name字段处理"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 看看个数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "57193"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(data['Employer_Name'].value_counts())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 名字的取值太多了，可以直接drop掉\n",
    "类似City字段"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#丢掉\n",
    "data.drop('Employer_Name',axis=1,inplace=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Existing_EMI字段"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x1115bccd0>"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {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bfQ7neTpvp7f2NtXSX57Xe2+JGeTfKi3/pYk7xlWL9JAj/yV\nRuRrVfU9gxZX1Y9tUvLzwO8AXx2wfjs+VlX/bIPtzwCTSV5eVV8DfgT4fztwfglw5K49Jsmrkjya\n5LW99U6St/aWP5dkf5LLk/zPJJ9K8pkkb07yc8CrgaUkS331B5MsJ3lvkoeT/FGSl/dq/nGSh5J8\nPMm7knzmItr/MPDjveVZoHMRx5IuyHDXbvbyvimON1fV06y9Gez9SY4C31xV7+373I3AE1X1+qqa\nBD5SVb/G2rt/Z6pqZoNzHQLurKrrgC8BP9Hb/pvA26rq+4HVAXr+wb6ev2PdvruAo0m+Afhu4JOD\n/WuQts5pGe1mG07LVNUfJ3kTcCfw+g0+92ngV5O8E/hQVX1sgHN9tqoe7C0/ABzszce/sqr+d2/7\n7wIbTbmsd75pGarqoSQHWRu1n9qoRhoWR+7ac5K8BJgAvgZ8S//+qvpz4B+xFvL/Ocnt/TUb+Ot1\ny6usDXxy8d2+yEngV3FKRjvMcNde9O9Ye1n7LPC+JC9dvzPJq4GvVtXvsBak39vb9RXglYOepKq+\nCHwlyff1Nh292MaB9wF3VNWnh3As6bycltFu9vIkD65b/whr4fivgeur6itJPgr8IvBL6+peB7wr\nyd8AXwd+trf9BPDhJE+eZ959I3PAe5M8A3SBpzep/8G+nv9TVX3wuZWqOgP81wHPLW2bz5aRLiDJ\nK6pqpbd8G/BtVfVvR9yWtClH7tKF/XiSd7D238rngbeMth1pMI7cpS1K8qPAO/s2f7aq/vko+pE2\nYrhLUoP8tYwkNchwl6QGGe6S1CDDXZIa9LcBDmc49mLPQQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1a17f45910>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "data.boxplot(column='Existing_EMI',return_type='axes')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "count    1.246260e+05\n",
       "mean     3.636342e+03\n",
       "std      3.369124e+04\n",
       "min      0.000000e+00\n",
       "25%      0.000000e+00\n",
       "50%      0.000000e+00\n",
       "75%      3.500000e+03\n",
       "max      1.000000e+07\n",
       "Name: Existing_EMI, dtype: float64"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data['Existing_EMI'].describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#缺省值不多，用均值代替\n",
    "# xgboost其实可以不用处理缺失值，xgboost可以自己处理\n",
    "data['Existing_EMI'].fillna(0, inplace=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Interest_Rate字段:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x1a19bdee10>"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD9CAYAAACsq4z3AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAADqNJREFUeJzt3X+MZWV9x/H3Z2FR3KViu3SyRXSa\nra0YGxecVCxtMoumIdpGTUqMaSwq3ZVEqlihEJv4M00wu8ofbdNkEQNpqPzwR7QL0lKciWIsOkuH\nBbomSsVGi6JWK7tpTdVv/5iDzsqdvXd+3Jm9z32/kpN7znOfc88XuHz22eece06qCknS6Nu00QVI\nktaGgS5JjTDQJakRBrokNcJAl6RGGOiS1AgDXZIaYaBLUiMMdElqxMnrebBt27bV5OTkeh5SGsjR\no0fZsmXLRpch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ax5ZZ46uT7AJ+A9hdVf/b\ntT8TuCXJ9q6mry6x/0uB5y2q6ReSnFZVjy+zDumnDHSdiH64aP3H9P6eBrirql6zxGcc7V43Ad+v\nhfnuY1TVpUleBLwcmE/ypD7HcUtVXZbkxcDtST5VVd8E/gr4QFV9Msk0CyPzXjYBL66q/1nGMaXj\ncg5do+Rx4LRu/V+A85P8GkCSpyX59Z/foap+AHw1yUVdvyR5Qbe+o6rurap3sHCnxbN+7hh9VdXn\ngb8D3tI1PR34Rrd+8RK1A/wTcNkTG8v8w0TqyUDXKNkPfCrJTFV9m4W57A8nOcRCwD93if3+CLgk\nyf3AQ8Aruva9SR5I8iAL8/H3AzMsTIUMdFK08z7g9UlOY2FEfluSz3Ls7Xj/AXjVEydFgTcDU0kO\nJfk3Fk6aSqviT/8lqRGO0CWpEZ4UlZaQ5PX8bG78CZ+rqjdtRD1SP065SFIjnHKRpEYY6JLUCANd\nkhphoEtSIwx0SWrE/wPbbflEQl8U8wAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1a17a80850>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "data.boxplot(column=['Interest_Rate'],return_type='axes')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   Interest_Rate  Interest_Rate_Missing\n",
      "0            NaN                      1\n",
      "1          13.25                      0\n",
      "2            NaN                      1\n",
      "3            NaN                      1\n",
      "4            NaN                      1\n",
      "5          13.99                      0\n",
      "6            NaN                      1\n",
      "7            NaN                      1\n",
      "8          14.85                      0\n",
      "9          18.25                      0\n"
     ]
    }
   ],
   "source": [
    "#缺省值太多，也造一个字段，表示有无\n",
    "data['Interest_Rate_Missing'] = data['Interest_Rate'].apply(lambda x: 1 if pd.isnull(x) else 0)\n",
    "print data[['Interest_Rate','Interest_Rate_Missing']].head(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "data.drop('Interest_Rate',axis=1,inplace=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Lead Creation Date字段"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Device_Type</th>\n",
       "      <th>Disbursed</th>\n",
       "      <th>EMI_Loan_Submitted</th>\n",
       "      <th>Existing_EMI</th>\n",
       "      <th>Filled_Form</th>\n",
       "      <th>Gender</th>\n",
       "      <th>ID</th>\n",
       "      <th>Loan_Amount_Applied</th>\n",
       "      <th>Loan_Amount_Submitted</th>\n",
       "      <th>Loan_Tenure_Applied</th>\n",
       "      <th>...</th>\n",
       "      <th>Salary_Account</th>\n",
       "      <th>Source</th>\n",
       "      <th>Var1</th>\n",
       "      <th>Var2</th>\n",
       "      <th>Var4</th>\n",
       "      <th>Var5</th>\n",
       "      <th>source</th>\n",
       "      <th>Age</th>\n",
       "      <th>EMI_Loan_Submitted_Missing</th>\n",
       "      <th>Interest_Rate_Missing</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Web-browser</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>N</td>\n",
       "      <td>Female</td>\n",
       "      <td>ID000002C20</td>\n",
       "      <td>300000.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>5.0</td>\n",
       "      <td>...</td>\n",
       "      <td>HDFC Bank</td>\n",
       "      <td>S122</td>\n",
       "      <td>HBXX</td>\n",
       "      <td>G</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>train</td>\n",
       "      <td>37</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Web-browser</td>\n",
       "      <td>0.0</td>\n",
       "      <td>6762.9</td>\n",
       "      <td>0.0</td>\n",
       "      <td>N</td>\n",
       "      <td>Male</td>\n",
       "      <td>ID000004E40</td>\n",
       "      <td>200000.0</td>\n",
       "      <td>200000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>...</td>\n",
       "      <td>ICICI Bank</td>\n",
       "      <td>S122</td>\n",
       "      <td>HBXA</td>\n",
       "      <td>G</td>\n",
       "      <td>3</td>\n",
       "      <td>13</td>\n",
       "      <td>train</td>\n",
       "      <td>30</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Web-browser</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>N</td>\n",
       "      <td>Male</td>\n",
       "      <td>ID000007H20</td>\n",
       "      <td>600000.0</td>\n",
       "      <td>450000.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>...</td>\n",
       "      <td>State Bank of India</td>\n",
       "      <td>S143</td>\n",
       "      <td>HBXX</td>\n",
       "      <td>B</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>train</td>\n",
       "      <td>34</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Web-browser</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>N</td>\n",
       "      <td>Male</td>\n",
       "      <td>ID000008I30</td>\n",
       "      <td>1000000.0</td>\n",
       "      <td>920000.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>...</td>\n",
       "      <td>State Bank of India</td>\n",
       "      <td>S143</td>\n",
       "      <td>HBXX</td>\n",
       "      <td>B</td>\n",
       "      <td>3</td>\n",
       "      <td>10</td>\n",
       "      <td>train</td>\n",
       "      <td>28</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Web-browser</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>25000.0</td>\n",
       "      <td>N</td>\n",
       "      <td>Male</td>\n",
       "      <td>ID000009J40</td>\n",
       "      <td>500000.0</td>\n",
       "      <td>500000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>...</td>\n",
       "      <td>HDFC Bank</td>\n",
       "      <td>S134</td>\n",
       "      <td>HBXX</td>\n",
       "      <td>B</td>\n",
       "      <td>3</td>\n",
       "      <td>17</td>\n",
       "      <td>train</td>\n",
       "      <td>31</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 25 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   Device_Type  Disbursed  EMI_Loan_Submitted  Existing_EMI Filled_Form  \\\n",
       "0  Web-browser        0.0                 NaN           0.0           N   \n",
       "1  Web-browser        0.0              6762.9           0.0           N   \n",
       "2  Web-browser        0.0                 NaN           0.0           N   \n",
       "3  Web-browser        0.0                 NaN           0.0           N   \n",
       "4  Web-browser        0.0                 NaN       25000.0           N   \n",
       "\n",
       "   Gender           ID  Loan_Amount_Applied  Loan_Amount_Submitted  \\\n",
       "0  Female  ID000002C20             300000.0                    NaN   \n",
       "1    Male  ID000004E40             200000.0               200000.0   \n",
       "2    Male  ID000007H20             600000.0               450000.0   \n",
       "3    Male  ID000008I30            1000000.0               920000.0   \n",
       "4    Male  ID000009J40             500000.0               500000.0   \n",
       "\n",
       "   Loan_Tenure_Applied          ...                 Salary_Account  Source  \\\n",
       "0                  5.0          ...                      HDFC Bank    S122   \n",
       "1                  2.0          ...                     ICICI Bank    S122   \n",
       "2                  4.0          ...            State Bank of India    S143   \n",
       "3                  5.0          ...            State Bank of India    S143   \n",
       "4                  2.0          ...                      HDFC Bank    S134   \n",
       "\n",
       "   Var1  Var2  Var4 Var5 source Age EMI_Loan_Submitted_Missing  \\\n",
       "0  HBXX     G     1    0  train  37                          1   \n",
       "1  HBXA     G     3   13  train  30                          0   \n",
       "2  HBXX     B     1    0  train  34                          1   \n",
       "3  HBXX     B     3   10  train  28                          1   \n",
       "4  HBXX     B     3   17  train  31                          1   \n",
       "\n",
       "   Interest_Rate_Missing  \n",
       "0                      1  \n",
       "1                      0  \n",
       "2                      1  \n",
       "3                      1  \n",
       "4                      1  \n",
       "\n",
       "[5 rows x 25 columns]"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#drop\n",
    "data.drop('Lead_Creation_Date',axis=1,inplace=True)\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Loan Amount and Tenure applied字段"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#找中位数去填补缺省值（因为缺省的不多）\n",
    "data['Loan_Amount_Applied'].fillna(data['Loan_Amount_Applied'].median(),inplace=True)\n",
    "data['Loan_Tenure_Applied'].fillna(data['Loan_Tenure_Applied'].median(),inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Device_Type</th>\n",
       "      <th>Disbursed</th>\n",
       "      <th>EMI_Loan_Submitted</th>\n",
       "      <th>Existing_EMI</th>\n",
       "      <th>Filled_Form</th>\n",
       "      <th>Gender</th>\n",
       "      <th>ID</th>\n",
       "      <th>Loan_Amount_Applied</th>\n",
       "      <th>Loan_Amount_Submitted</th>\n",
       "      <th>Loan_Tenure_Applied</th>\n",
       "      <th>...</th>\n",
       "      <th>Salary_Account</th>\n",
       "      <th>Source</th>\n",
       "      <th>Var1</th>\n",
       "      <th>Var2</th>\n",
       "      <th>Var4</th>\n",
       "      <th>Var5</th>\n",
       "      <th>source</th>\n",
       "      <th>Age</th>\n",
       "      <th>EMI_Loan_Submitted_Missing</th>\n",
       "      <th>Interest_Rate_Missing</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Web-browser</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>N</td>\n",
       "      <td>Female</td>\n",
       "      <td>ID000002C20</td>\n",
       "      <td>300000.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>5.0</td>\n",
       "      <td>...</td>\n",
       "      <td>HDFC Bank</td>\n",
       "      <td>S122</td>\n",
       "      <td>HBXX</td>\n",
       "      <td>G</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>train</td>\n",
       "      <td>37</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Web-browser</td>\n",
       "      <td>0.0</td>\n",
       "      <td>6762.9</td>\n",
       "      <td>0.0</td>\n",
       "      <td>N</td>\n",
       "      <td>Male</td>\n",
       "      <td>ID000004E40</td>\n",
       "      <td>200000.0</td>\n",
       "      <td>200000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>...</td>\n",
       "      <td>ICICI Bank</td>\n",
       "      <td>S122</td>\n",
       "      <td>HBXA</td>\n",
       "      <td>G</td>\n",
       "      <td>3</td>\n",
       "      <td>13</td>\n",
       "      <td>train</td>\n",
       "      <td>30</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Web-browser</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>N</td>\n",
       "      <td>Male</td>\n",
       "      <td>ID000007H20</td>\n",
       "      <td>600000.0</td>\n",
       "      <td>450000.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>...</td>\n",
       "      <td>State Bank of India</td>\n",
       "      <td>S143</td>\n",
       "      <td>HBXX</td>\n",
       "      <td>B</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>train</td>\n",
       "      <td>34</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Web-browser</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>N</td>\n",
       "      <td>Male</td>\n",
       "      <td>ID000008I30</td>\n",
       "      <td>1000000.0</td>\n",
       "      <td>920000.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>...</td>\n",
       "      <td>State Bank of India</td>\n",
       "      <td>S143</td>\n",
       "      <td>HBXX</td>\n",
       "      <td>B</td>\n",
       "      <td>3</td>\n",
       "      <td>10</td>\n",
       "      <td>train</td>\n",
       "      <td>28</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Web-browser</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>25000.0</td>\n",
       "      <td>N</td>\n",
       "      <td>Male</td>\n",
       "      <td>ID000009J40</td>\n",
       "      <td>500000.0</td>\n",
       "      <td>500000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>...</td>\n",
       "      <td>HDFC Bank</td>\n",
       "      <td>S134</td>\n",
       "      <td>HBXX</td>\n",
       "      <td>B</td>\n",
       "      <td>3</td>\n",
       "      <td>17</td>\n",
       "      <td>train</td>\n",
       "      <td>31</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 25 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   Device_Type  Disbursed  EMI_Loan_Submitted  Existing_EMI Filled_Form  \\\n",
       "0  Web-browser        0.0                 NaN           0.0           N   \n",
       "1  Web-browser        0.0              6762.9           0.0           N   \n",
       "2  Web-browser        0.0                 NaN           0.0           N   \n",
       "3  Web-browser        0.0                 NaN           0.0           N   \n",
       "4  Web-browser        0.0                 NaN       25000.0           N   \n",
       "\n",
       "   Gender           ID  Loan_Amount_Applied  Loan_Amount_Submitted  \\\n",
       "0  Female  ID000002C20             300000.0                    NaN   \n",
       "1    Male  ID000004E40             200000.0               200000.0   \n",
       "2    Male  ID000007H20             600000.0               450000.0   \n",
       "3    Male  ID000008I30            1000000.0               920000.0   \n",
       "4    Male  ID000009J40             500000.0               500000.0   \n",
       "\n",
       "   Loan_Tenure_Applied          ...                 Salary_Account  Source  \\\n",
       "0                  5.0          ...                      HDFC Bank    S122   \n",
       "1                  2.0          ...                     ICICI Bank    S122   \n",
       "2                  4.0          ...            State Bank of India    S143   \n",
       "3                  5.0          ...            State Bank of India    S143   \n",
       "4                  2.0          ...                      HDFC Bank    S134   \n",
       "\n",
       "   Var1  Var2  Var4 Var5 source Age EMI_Loan_Submitted_Missing  \\\n",
       "0  HBXX     G     1    0  train  37                          1   \n",
       "1  HBXA     G     3   13  train  30                          0   \n",
       "2  HBXX     B     1    0  train  34                          1   \n",
       "3  HBXX     B     3   10  train  28                          1   \n",
       "4  HBXX     B     3   17  train  31                          1   \n",
       "\n",
       "   Interest_Rate_Missing  \n",
       "0                      1  \n",
       "1                      0  \n",
       "2                      1  \n",
       "3                      1  \n",
       "4                      1  \n",
       "\n",
       "[5 rows x 25 columns]"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Loan Amount and Tenure selected"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 缺省值太多。。。是否缺省。。。\n",
    "data['Loan_Amount_Submitted_Missing'] = data['Loan_Amount_Submitted'].apply(lambda x: 1 if pd.isnull(x) else 0)\n",
    "data['Loan_Tenure_Submitted_Missing'] = data['Loan_Tenure_Submitted'].apply(lambda x: 1 if pd.isnull(x) else 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Device_Type</th>\n",
       "      <th>Disbursed</th>\n",
       "      <th>EMI_Loan_Submitted</th>\n",
       "      <th>Existing_EMI</th>\n",
       "      <th>Filled_Form</th>\n",
       "      <th>Gender</th>\n",
       "      <th>ID</th>\n",
       "      <th>Loan_Amount_Applied</th>\n",
       "      <th>Loan_Amount_Submitted</th>\n",
       "      <th>Loan_Tenure_Applied</th>\n",
       "      <th>...</th>\n",
       "      <th>Var1</th>\n",
       "      <th>Var2</th>\n",
       "      <th>Var4</th>\n",
       "      <th>Var5</th>\n",
       "      <th>source</th>\n",
       "      <th>Age</th>\n",
       "      <th>EMI_Loan_Submitted_Missing</th>\n",
       "      <th>Interest_Rate_Missing</th>\n",
       "      <th>Loan_Amount_Submitted_Missing</th>\n",
       "      <th>Loan_Tenure_Submitted_Missing</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Web-browser</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>N</td>\n",
       "      <td>Female</td>\n",
       "      <td>ID000002C20</td>\n",
       "      <td>300000.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>5.0</td>\n",
       "      <td>...</td>\n",
       "      <td>HBXX</td>\n",
       "      <td>G</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>train</td>\n",
       "      <td>37</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Web-browser</td>\n",
       "      <td>0.0</td>\n",
       "      <td>6762.9</td>\n",
       "      <td>0.0</td>\n",
       "      <td>N</td>\n",
       "      <td>Male</td>\n",
       "      <td>ID000004E40</td>\n",
       "      <td>200000.0</td>\n",
       "      <td>200000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>...</td>\n",
       "      <td>HBXA</td>\n",
       "      <td>G</td>\n",
       "      <td>3</td>\n",
       "      <td>13</td>\n",
       "      <td>train</td>\n",
       "      <td>30</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Web-browser</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>N</td>\n",
       "      <td>Male</td>\n",
       "      <td>ID000007H20</td>\n",
       "      <td>600000.0</td>\n",
       "      <td>450000.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>...</td>\n",
       "      <td>HBXX</td>\n",
       "      <td>B</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>train</td>\n",
       "      <td>34</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Web-browser</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>N</td>\n",
       "      <td>Male</td>\n",
       "      <td>ID000008I30</td>\n",
       "      <td>1000000.0</td>\n",
       "      <td>920000.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>...</td>\n",
       "      <td>HBXX</td>\n",
       "      <td>B</td>\n",
       "      <td>3</td>\n",
       "      <td>10</td>\n",
       "      <td>train</td>\n",
       "      <td>28</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Web-browser</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>25000.0</td>\n",
       "      <td>N</td>\n",
       "      <td>Male</td>\n",
       "      <td>ID000009J40</td>\n",
       "      <td>500000.0</td>\n",
       "      <td>500000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>...</td>\n",
       "      <td>HBXX</td>\n",
       "      <td>B</td>\n",
       "      <td>3</td>\n",
       "      <td>17</td>\n",
       "      <td>train</td>\n",
       "      <td>31</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 27 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   Device_Type  Disbursed  EMI_Loan_Submitted  Existing_EMI Filled_Form  \\\n",
       "0  Web-browser        0.0                 NaN           0.0           N   \n",
       "1  Web-browser        0.0              6762.9           0.0           N   \n",
       "2  Web-browser        0.0                 NaN           0.0           N   \n",
       "3  Web-browser        0.0                 NaN           0.0           N   \n",
       "4  Web-browser        0.0                 NaN       25000.0           N   \n",
       "\n",
       "   Gender           ID  Loan_Amount_Applied  Loan_Amount_Submitted  \\\n",
       "0  Female  ID000002C20             300000.0                    NaN   \n",
       "1    Male  ID000004E40             200000.0               200000.0   \n",
       "2    Male  ID000007H20             600000.0               450000.0   \n",
       "3    Male  ID000008I30            1000000.0               920000.0   \n",
       "4    Male  ID000009J40             500000.0               500000.0   \n",
       "\n",
       "   Loan_Tenure_Applied              ...                Var1  Var2 Var4  Var5  \\\n",
       "0                  5.0              ...                HBXX     G    1     0   \n",
       "1                  2.0              ...                HBXA     G    3    13   \n",
       "2                  4.0              ...                HBXX     B    1     0   \n",
       "3                  5.0              ...                HBXX     B    3    10   \n",
       "4                  2.0              ...                HBXX     B    3    17   \n",
       "\n",
       "   source Age EMI_Loan_Submitted_Missing Interest_Rate_Missing  \\\n",
       "0   train  37                          1                     1   \n",
       "1   train  30                          0                     0   \n",
       "2   train  34                          1                     1   \n",
       "3   train  28                          1                     1   \n",
       "4   train  31                          1                     1   \n",
       "\n",
       "  Loan_Amount_Submitted_Missing  Loan_Tenure_Submitted_Missing  \n",
       "0                             1                              1  \n",
       "1                             0                              0  \n",
       "2                             0                              0  \n",
       "3                             0                              0  \n",
       "4                             0                              0  \n",
       "\n",
       "[5 rows x 27 columns]"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#原来的字段就没用了\n",
    "data.drop(['Loan_Amount_Submitted','Loan_Tenure_Submitted'],axis=1,inplace=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### LoggedIn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#没想好怎么用\n",
    "data.drop('LoggedIn',axis=1,inplace=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### salary account"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 可能对接多个银行，所以也不要了\n",
    "#data.drop('Salary_Account',axis=1,inplace=True)\n",
    "\n",
    "def dictMap(listOfMajors, non_major):\n",
    "    mapped_dict = {}\n",
    "    for i, major in enumerate(reversed(listOfMajors)):\n",
    "        mapped_dict[major] = (i+1)\n",
    "    mapped_dict[non_major] = 0\n",
    "    return mapped_dict\n",
    "\n",
    "#训练集中前20个银行为主要银行，其他编码为非主要银行\n",
    "#City，Employer_Name等字段亦可采用这种方式\n",
    "bank_counts = train.Salary_Account.value_counts()\n",
    "major_banks = list(bank_counts.index[:20])\n",
    "\n",
    "data.loc[ ~data['Salary_Account'].isin(major_banks), 'Salary_Account' ] = 'Non-major bank'\n",
    "mapped_banks = dictMap(major_banks, 'Non-major bank')\n",
    "\n",
    "#编码成整数\n",
    "data['Salary_Account'] = data['Salary_Account'].map( mapped_banks ).astype(int)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Processing_Fee"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#和之前一样的处理，有或者没有\n",
    "data['Processing_Fee_Missing'] = data['Processing_Fee'].apply(lambda x: 1 if pd.isnull(x) else 0)\n",
    "#旧的字段不要了\n",
    "data.drop('Processing_Fee',axis=1,inplace=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Source"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "S122      55249\n",
       "S133      42900\n",
       "others    26588\n",
       "Name: Source, dtype: int64"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data['Source'] = data['Source'].apply(lambda x: 'others' if x not in ['S122','S133'] else x)\n",
    "data['Source'].value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 最终的数据样式"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Device_Type</th>\n",
       "      <th>Disbursed</th>\n",
       "      <th>EMI_Loan_Submitted</th>\n",
       "      <th>Existing_EMI</th>\n",
       "      <th>Filled_Form</th>\n",
       "      <th>Gender</th>\n",
       "      <th>ID</th>\n",
       "      <th>Loan_Amount_Applied</th>\n",
       "      <th>Loan_Tenure_Applied</th>\n",
       "      <th>Mobile_Verified</th>\n",
       "      <th>...</th>\n",
       "      <th>Var2</th>\n",
       "      <th>Var4</th>\n",
       "      <th>Var5</th>\n",
       "      <th>source</th>\n",
       "      <th>Age</th>\n",
       "      <th>EMI_Loan_Submitted_Missing</th>\n",
       "      <th>Interest_Rate_Missing</th>\n",
       "      <th>Loan_Amount_Submitted_Missing</th>\n",
       "      <th>Loan_Tenure_Submitted_Missing</th>\n",
       "      <th>Processing_Fee_Missing</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Web-browser</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>N</td>\n",
       "      <td>Female</td>\n",
       "      <td>ID000002C20</td>\n",
       "      <td>300000.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>N</td>\n",
       "      <td>...</td>\n",
       "      <td>G</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>train</td>\n",
       "      <td>37</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Web-browser</td>\n",
       "      <td>0.0</td>\n",
       "      <td>6762.9</td>\n",
       "      <td>0.0</td>\n",
       "      <td>N</td>\n",
       "      <td>Male</td>\n",
       "      <td>ID000004E40</td>\n",
       "      <td>200000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>Y</td>\n",
       "      <td>...</td>\n",
       "      <td>G</td>\n",
       "      <td>3</td>\n",
       "      <td>13</td>\n",
       "      <td>train</td>\n",
       "      <td>30</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Web-browser</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>N</td>\n",
       "      <td>Male</td>\n",
       "      <td>ID000007H20</td>\n",
       "      <td>600000.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>Y</td>\n",
       "      <td>...</td>\n",
       "      <td>B</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>train</td>\n",
       "      <td>34</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Web-browser</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>N</td>\n",
       "      <td>Male</td>\n",
       "      <td>ID000008I30</td>\n",
       "      <td>1000000.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>Y</td>\n",
       "      <td>...</td>\n",
       "      <td>B</td>\n",
       "      <td>3</td>\n",
       "      <td>10</td>\n",
       "      <td>train</td>\n",
       "      <td>28</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Web-browser</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>25000.0</td>\n",
       "      <td>N</td>\n",
       "      <td>Male</td>\n",
       "      <td>ID000009J40</td>\n",
       "      <td>500000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>Y</td>\n",
       "      <td>...</td>\n",
       "      <td>B</td>\n",
       "      <td>3</td>\n",
       "      <td>17</td>\n",
       "      <td>train</td>\n",
       "      <td>31</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 24 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   Device_Type  Disbursed  EMI_Loan_Submitted  Existing_EMI Filled_Form  \\\n",
       "0  Web-browser        0.0                 NaN           0.0           N   \n",
       "1  Web-browser        0.0              6762.9           0.0           N   \n",
       "2  Web-browser        0.0                 NaN           0.0           N   \n",
       "3  Web-browser        0.0                 NaN           0.0           N   \n",
       "4  Web-browser        0.0                 NaN       25000.0           N   \n",
       "\n",
       "   Gender           ID  Loan_Amount_Applied  Loan_Tenure_Applied  \\\n",
       "0  Female  ID000002C20             300000.0                  5.0   \n",
       "1    Male  ID000004E40             200000.0                  2.0   \n",
       "2    Male  ID000007H20             600000.0                  4.0   \n",
       "3    Male  ID000008I30            1000000.0                  5.0   \n",
       "4    Male  ID000009J40             500000.0                  2.0   \n",
       "\n",
       "  Mobile_Verified           ...            Var2  Var4 Var5 source Age  \\\n",
       "0               N           ...               G     1    0  train  37   \n",
       "1               Y           ...               G     3   13  train  30   \n",
       "2               Y           ...               B     1    0  train  34   \n",
       "3               Y           ...               B     3   10  train  28   \n",
       "4               Y           ...               B     3   17  train  31   \n",
       "\n",
       "   EMI_Loan_Submitted_Missing  Interest_Rate_Missing  \\\n",
       "0                           1                      1   \n",
       "1                           0                      0   \n",
       "2                           1                      1   \n",
       "3                           1                      1   \n",
       "4                           1                      1   \n",
       "\n",
       "  Loan_Amount_Submitted_Missing  Loan_Tenure_Submitted_Missing  \\\n",
       "0                             1                              1   \n",
       "1                             0                              0   \n",
       "2                             0                              0   \n",
       "3                             0                              0   \n",
       "4                             0                              0   \n",
       "\n",
       "   Processing_Fee_Missing  \n",
       "0                       1  \n",
       "1                       1  \n",
       "2                       1  \n",
       "3                       1  \n",
       "4                       1  \n",
       "\n",
       "[5 rows x 24 columns]"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Disbursed</th>\n",
       "      <th>EMI_Loan_Submitted</th>\n",
       "      <th>Existing_EMI</th>\n",
       "      <th>Loan_Amount_Applied</th>\n",
       "      <th>Loan_Tenure_Applied</th>\n",
       "      <th>Monthly_Income</th>\n",
       "      <th>Salary_Account</th>\n",
       "      <th>Var4</th>\n",
       "      <th>Var5</th>\n",
       "      <th>Age</th>\n",
       "      <th>EMI_Loan_Submitted_Missing</th>\n",
       "      <th>Interest_Rate_Missing</th>\n",
       "      <th>Loan_Amount_Submitted_Missing</th>\n",
       "      <th>Loan_Tenure_Submitted_Missing</th>\n",
       "      <th>Processing_Fee_Missing</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>87020.000000</td>\n",
       "      <td>39836.000000</td>\n",
       "      <td>1.247370e+05</td>\n",
       "      <td>1.247370e+05</td>\n",
       "      <td>124737.000000</td>\n",
       "      <td>1.247370e+05</td>\n",
       "      <td>124737.000000</td>\n",
       "      <td>124737.000000</td>\n",
       "      <td>124737.000000</td>\n",
       "      <td>124737.000000</td>\n",
       "      <td>124737.000000</td>\n",
       "      <td>124737.000000</td>\n",
       "      <td>124737.000000</td>\n",
       "      <td>124737.000000</td>\n",
       "      <td>124737.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>0.014629</td>\n",
       "      <td>10982.549579</td>\n",
       "      <td>3.633107e+03</td>\n",
       "      <td>2.298744e+05</td>\n",
       "      <td>2.138075</td>\n",
       "      <td>5.309073e+04</td>\n",
       "      <td>13.250631</td>\n",
       "      <td>2.950560</td>\n",
       "      <td>4.964774</td>\n",
       "      <td>30.906996</td>\n",
       "      <td>0.680640</td>\n",
       "      <td>0.680640</td>\n",
       "      <td>0.397116</td>\n",
       "      <td>0.397116</td>\n",
       "      <td>0.684208</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>0.120062</td>\n",
       "      <td>7466.525227</td>\n",
       "      <td>3.367642e+04</td>\n",
       "      <td>3.539938e+05</td>\n",
       "      <td>2.014874</td>\n",
       "      <td>1.823394e+06</td>\n",
       "      <td>7.807525</td>\n",
       "      <td>1.695261</td>\n",
       "      <td>5.669784</td>\n",
       "      <td>7.137860</td>\n",
       "      <td>0.466231</td>\n",
       "      <td>0.466231</td>\n",
       "      <td>0.489302</td>\n",
       "      <td>0.489302</td>\n",
       "      <td>0.464833</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>1176.410000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>18.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>6390.380000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.650000e+04</td>\n",
       "      <td>6.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>26.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>9409.230000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>1.000000e+05</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>2.500000e+04</td>\n",
       "      <td>17.000000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>29.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>12909.270000</td>\n",
       "      <td>3.500000e+03</td>\n",
       "      <td>3.000000e+05</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>4.000000e+04</td>\n",
       "      <td>19.000000</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>11.000000</td>\n",
       "      <td>34.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>144748.280000</td>\n",
       "      <td>1.000000e+07</td>\n",
       "      <td>1.500000e+07</td>\n",
       "      <td>10.000000</td>\n",
       "      <td>4.445544e+08</td>\n",
       "      <td>20.000000</td>\n",
       "      <td>7.000000</td>\n",
       "      <td>18.000000</td>\n",
       "      <td>100.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          Disbursed  EMI_Loan_Submitted  Existing_EMI  Loan_Amount_Applied  \\\n",
       "count  87020.000000        39836.000000  1.247370e+05         1.247370e+05   \n",
       "mean       0.014629        10982.549579  3.633107e+03         2.298744e+05   \n",
       "std        0.120062         7466.525227  3.367642e+04         3.539938e+05   \n",
       "min        0.000000         1176.410000  0.000000e+00         0.000000e+00   \n",
       "25%        0.000000         6390.380000  0.000000e+00         0.000000e+00   \n",
       "50%        0.000000         9409.230000  0.000000e+00         1.000000e+05   \n",
       "75%        0.000000        12909.270000  3.500000e+03         3.000000e+05   \n",
       "max        1.000000       144748.280000  1.000000e+07         1.500000e+07   \n",
       "\n",
       "       Loan_Tenure_Applied  Monthly_Income  Salary_Account           Var4  \\\n",
       "count        124737.000000    1.247370e+05   124737.000000  124737.000000   \n",
       "mean              2.138075    5.309073e+04       13.250631       2.950560   \n",
       "std               2.014874    1.823394e+06        7.807525       1.695261   \n",
       "min               0.000000    0.000000e+00        0.000000       0.000000   \n",
       "25%               0.000000    1.650000e+04        6.000000       1.000000   \n",
       "50%               2.000000    2.500000e+04       17.000000       3.000000   \n",
       "75%               4.000000    4.000000e+04       19.000000       5.000000   \n",
       "max              10.000000    4.445544e+08       20.000000       7.000000   \n",
       "\n",
       "                Var5            Age  EMI_Loan_Submitted_Missing  \\\n",
       "count  124737.000000  124737.000000               124737.000000   \n",
       "mean        4.964774      30.906996                    0.680640   \n",
       "std         5.669784       7.137860                    0.466231   \n",
       "min         0.000000      18.000000                    0.000000   \n",
       "25%         0.000000      26.000000                    0.000000   \n",
       "50%         2.000000      29.000000                    1.000000   \n",
       "75%        11.000000      34.000000                    1.000000   \n",
       "max        18.000000     100.000000                    1.000000   \n",
       "\n",
       "       Interest_Rate_Missing  Loan_Amount_Submitted_Missing  \\\n",
       "count          124737.000000                  124737.000000   \n",
       "mean                0.680640                       0.397116   \n",
       "std                 0.466231                       0.489302   \n",
       "min                 0.000000                       0.000000   \n",
       "25%                 0.000000                       0.000000   \n",
       "50%                 1.000000                       0.000000   \n",
       "75%                 1.000000                       1.000000   \n",
       "max                 1.000000                       1.000000   \n",
       "\n",
       "       Loan_Tenure_Submitted_Missing  Processing_Fee_Missing  \n",
       "count                  124737.000000           124737.000000  \n",
       "mean                        0.397116                0.684208  \n",
       "std                         0.489302                0.464833  \n",
       "min                         0.000000                0.000000  \n",
       "25%                         0.000000                0.000000  \n",
       "50%                         0.000000                1.000000  \n",
       "75%                         1.000000                1.000000  \n",
       "max                         1.000000                1.000000  "
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Device_Type                          0\n",
       "Disbursed                        37717\n",
       "EMI_Loan_Submitted               84901\n",
       "Existing_EMI                         0\n",
       "Filled_Form                          0\n",
       "Gender                               0\n",
       "ID                                   0\n",
       "Loan_Amount_Applied                  0\n",
       "Loan_Tenure_Applied                  0\n",
       "Mobile_Verified                      0\n",
       "Monthly_Income                       0\n",
       "Salary_Account                       0\n",
       "Source                               0\n",
       "Var1                                 0\n",
       "Var2                                 0\n",
       "Var4                                 0\n",
       "Var5                                 0\n",
       "source                               0\n",
       "Age                                  0\n",
       "EMI_Loan_Submitted_Missing           0\n",
       "Interest_Rate_Missing                0\n",
       "Loan_Amount_Submitted_Missing        0\n",
       "Loan_Tenure_Submitted_Missing        0\n",
       "Processing_Fee_Missing               0\n",
       "dtype: int64"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.apply(lambda x: sum(x.isnull()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Device_Type                       object\n",
       "Disbursed                        float64\n",
       "EMI_Loan_Submitted               float64\n",
       "Existing_EMI                     float64\n",
       "Filled_Form                       object\n",
       "Gender                            object\n",
       "ID                                object\n",
       "Loan_Amount_Applied              float64\n",
       "Loan_Tenure_Applied              float64\n",
       "Mobile_Verified                   object\n",
       "Monthly_Income                     int64\n",
       "Salary_Account                     int64\n",
       "Source                            object\n",
       "Var1                              object\n",
       "Var2                              object\n",
       "Var4                               int64\n",
       "Var5                               int64\n",
       "source                            object\n",
       "Age                                int64\n",
       "EMI_Loan_Submitted_Missing         int64\n",
       "Interest_Rate_Missing              int64\n",
       "Loan_Amount_Submitted_Missing      int64\n",
       "Loan_Tenure_Submitted_Missing      int64\n",
       "Processing_Fee_Missing             int64\n",
       "dtype: object"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.dtypes"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 数值编码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from sklearn.preprocessing import LabelEncoder\n",
    "le = LabelEncoder()\n",
    "var_to_encode = ['Device_Type','Filled_Form','Gender','Var1','Var2','Mobile_Verified','Source']\n",
    "for col in var_to_encode:\n",
    "    data[col] = le.fit_transform(data[col])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Device_Type</th>\n",
       "      <th>Disbursed</th>\n",
       "      <th>EMI_Loan_Submitted</th>\n",
       "      <th>Existing_EMI</th>\n",
       "      <th>Filled_Form</th>\n",
       "      <th>Gender</th>\n",
       "      <th>ID</th>\n",
       "      <th>Loan_Amount_Applied</th>\n",
       "      <th>Loan_Tenure_Applied</th>\n",
       "      <th>Mobile_Verified</th>\n",
       "      <th>...</th>\n",
       "      <th>Var2</th>\n",
       "      <th>Var4</th>\n",
       "      <th>Var5</th>\n",
       "      <th>source</th>\n",
       "      <th>Age</th>\n",
       "      <th>EMI_Loan_Submitted_Missing</th>\n",
       "      <th>Interest_Rate_Missing</th>\n",
       "      <th>Loan_Amount_Submitted_Missing</th>\n",
       "      <th>Loan_Tenure_Submitted_Missing</th>\n",
       "      <th>Processing_Fee_Missing</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>ID000002C20</td>\n",
       "      <td>300000.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>6</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>train</td>\n",
       "      <td>37</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>6762.9</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>ID000004E40</td>\n",
       "      <td>200000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>6</td>\n",
       "      <td>3</td>\n",
       "      <td>13</td>\n",
       "      <td>train</td>\n",
       "      <td>30</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>ID000007H20</td>\n",
       "      <td>600000.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>train</td>\n",
       "      <td>34</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>ID000008I30</td>\n",
       "      <td>1000000.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>10</td>\n",
       "      <td>train</td>\n",
       "      <td>28</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>25000.0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>ID000009J40</td>\n",
       "      <td>500000.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>17</td>\n",
       "      <td>train</td>\n",
       "      <td>31</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 24 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   Device_Type  Disbursed  EMI_Loan_Submitted  Existing_EMI  Filled_Form  \\\n",
       "0            1        0.0                 NaN           0.0            0   \n",
       "1            1        0.0              6762.9           0.0            0   \n",
       "2            1        0.0                 NaN           0.0            0   \n",
       "3            1        0.0                 NaN           0.0            0   \n",
       "4            1        0.0                 NaN       25000.0            0   \n",
       "\n",
       "   Gender           ID  Loan_Amount_Applied  Loan_Tenure_Applied  \\\n",
       "0       0  ID000002C20             300000.0                  5.0   \n",
       "1       1  ID000004E40             200000.0                  2.0   \n",
       "2       1  ID000007H20             600000.0                  4.0   \n",
       "3       1  ID000008I30            1000000.0                  5.0   \n",
       "4       1  ID000009J40             500000.0                  2.0   \n",
       "\n",
       "   Mobile_Verified           ...            Var2  Var4  Var5  source  Age  \\\n",
       "0                0           ...               6     1     0   train   37   \n",
       "1                1           ...               6     3    13   train   30   \n",
       "2                1           ...               1     1     0   train   34   \n",
       "3                1           ...               1     3    10   train   28   \n",
       "4                1           ...               1     3    17   train   31   \n",
       "\n",
       "   EMI_Loan_Submitted_Missing  Interest_Rate_Missing  \\\n",
       "0                           1                      1   \n",
       "1                           0                      0   \n",
       "2                           1                      1   \n",
       "3                           1                      1   \n",
       "4                           1                      1   \n",
       "\n",
       "  Loan_Amount_Submitted_Missing  Loan_Tenure_Submitted_Missing  \\\n",
       "0                             1                              1   \n",
       "1                             0                              0   \n",
       "2                             0                              0   \n",
       "3                             0                              0   \n",
       "4                             0                              0   \n",
       "\n",
       "   Processing_Fee_Missing  \n",
       "0                       1  \n",
       "1                       1  \n",
       "2                       1  \n",
       "3                       1  \n",
       "4                       1  \n",
       "\n",
       "[5 rows x 24 columns]"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Device_Type                        int64\n",
       "Disbursed                        float64\n",
       "EMI_Loan_Submitted               float64\n",
       "Existing_EMI                     float64\n",
       "Filled_Form                        int64\n",
       "Gender                             int64\n",
       "ID                                object\n",
       "Loan_Amount_Applied              float64\n",
       "Loan_Tenure_Applied              float64\n",
       "Mobile_Verified                    int64\n",
       "Monthly_Income                     int64\n",
       "Salary_Account                     int64\n",
       "Source                             int64\n",
       "Var1                               int64\n",
       "Var2                               int64\n",
       "Var4                               int64\n",
       "Var5                               int64\n",
       "source                            object\n",
       "Age                                int64\n",
       "EMI_Loan_Submitted_Missing         int64\n",
       "Interest_Rate_Missing              int64\n",
       "Loan_Amount_Submitted_Missing      int64\n",
       "Loan_Tenure_Submitted_Missing      int64\n",
       "Processing_Fee_Missing             int64\n",
       "dtype: object"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.dtypes"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 类别型的One-Hot 编码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index([u'Disbursed', u'EMI_Loan_Submitted', u'Existing_EMI', u'ID',\n",
       "       u'Loan_Amount_Applied', u'Loan_Tenure_Applied', u'Monthly_Income',\n",
       "       u'Salary_Account', u'Var4', u'Var5', u'source', u'Age',\n",
       "       u'EMI_Loan_Submitted_Missing', u'Interest_Rate_Missing',\n",
       "       u'Loan_Amount_Submitted_Missing', u'Loan_Tenure_Submitted_Missing',\n",
       "       u'Processing_Fee_Missing', u'Device_Type_0', u'Device_Type_1',\n",
       "       u'Filled_Form_0', u'Filled_Form_1', u'Gender_0', u'Gender_1', u'Var1_0',\n",
       "       u'Var1_1', u'Var1_2', u'Var1_3', u'Var1_4', u'Var1_5', u'Var1_6',\n",
       "       u'Var1_7', u'Var1_8', u'Var1_9', u'Var1_10', u'Var1_11', u'Var1_12',\n",
       "       u'Var1_13', u'Var1_14', u'Var1_15', u'Var1_16', u'Var1_17', u'Var1_18',\n",
       "       u'Var2_0', u'Var2_1', u'Var2_2', u'Var2_3', u'Var2_4', u'Var2_5',\n",
       "       u'Var2_6', u'Mobile_Verified_0', u'Mobile_Verified_1', u'Source_0',\n",
       "       u'Source_1', u'Source_2'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = pd.get_dummies(data, columns=var_to_encode)\n",
    "data.columns"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 区分训练和测试数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "train = data.loc[data['source']=='train']\n",
    "test = data.loc[data['source']=='test']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/qing/anaconda2/lib/python2.7/site-packages/ipykernel_launcher.py:1: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n",
      "  \"\"\"Entry point for launching an IPython kernel.\n",
      "/Users/qing/anaconda2/lib/python2.7/site-packages/ipykernel_launcher.py:2: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n",
      "  \n"
     ]
    }
   ],
   "source": [
    "train.drop('source',axis=1,inplace=True)\n",
    "test.drop(['source','Disbursed'],axis=1,inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "train.to_csv('train_modified.csv',index=False)\n",
    "test.to_csv('test_modified.csv',index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
